<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文件上传</title>
<link rel="stylesheet" href="<%=basePath %>/bootstrap/css/bootstrap.min.css">

    <script src="<%=basePath %>/js/jquery.min.js"></script>
	<script src="<%=basePath %>/bootstrap/js/bootstrap.min.js"></script>


	<link rel="stylesheet" href="<%=basePath%>/css/toastr.min.css">
	<script src="<%=basePath%>/js/toastr.min.js"></script>
	<script src="<%=basePath%>/js/toastrinit.js"></script>

	<link rel="stylesheet"	href="<%=basePath%>/plugins/uploadfive/uploadifive.css">
	<script src="<%=basePath%>/plugins/uploadfive/jquery.uploadifive.js"></script>
	
<script type="text/javascript">
$(document).ready(function(){
	$("#input_id").uploadifive({ 
        'fileObjName': 'fileData', 
        'auto': false, 
        'buttonText': "<spring:message code='file.choose' />", 
        'height': '30', 
        'width': '180', 
        'removeCompleted': false, 
        //'fileType':'application\/pdf',  //限制上传类型
        'uploadScript': '<%=basePath%>/file/upload.do',
        'queueID': 'fileQueue', 
         'multi': false,
         'onUploadComplete':function(file,data){
        	 if(data.msg=="success"){
             	toastr.success("<spring:message code='base.success' />");
        	 }else{
        		 toastr.error("<spring:message code='file.error' />");
        	 }
         },
         'onAddQueueItem' : function(file) { //文件选择后执行

            if(file.size > 209715200){
                toastr.error("<spring:message code='file.size.errormsg' />");
                   $("#input_id").uploadifive('cancel',file);
            }

            var queueCount =$('#filesList>li').length + $('#fileQueue>div').length;//所有的队列
            if(queueCount >1){
                  toastr.error("<spring:message code='file.selectmax.msg' />");
                  $("#input_id").uploadifive('cancel',file);
             }
         },
     });

	
	
	 $("#btn_upload").click(function(){
		$('#input_id').data('uploadifive').settings.formData = {typeKey:"ADMIN", type:"ADMIN"};   //动态更改formData的值
  		$('#input_id').uploadifive('upload');
     }); //end btn_upload

	
});//document结束


</script>

</head>
<body >
<br/>
<div class="container">

	<div class="row clearfix">
	<!-- 上传文件 -->	
		<form class="form-horizontal" id = "file_form">
		  <div class="form-group">
			<!-- 上传按钮 -->
			<label for="file" class="col-sm-3 control-label"></label>
			  <div class="text-right col-sm-6">
			    <input id="input_id" name="file" type="file" class="file">
			  </div>
			</div>
			
			<div class="form-group">
			  <!-- 待上传队列 -->
			  <label for="file" class="col-sm-3 control-label"></label>
			  <div class="col-sm-6" id="fileQueue"></div>
			</div>
					  
		</form>
	</div>
	<div  style="text-align:center">   
	  <button id="btn_upload" 	type="button" class="btn btn-primary"><spring:message code='file.upload' /></button>
	</div>
		
</div>

</body>
</html>